package android.cs2340UDT;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.app.Activity;
import android.content.Intent;

/*
 * This class displays the current user's information. Right now that is only items. Note: There will be
 *  so many more buttons to come
 */
public class MainScreenActivity extends Activity implements OnClickListener{
	 /** Called when the activity is first created. */
	
	Manager manage = Security.getManager();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_screen);
    
        ImageButton BackButton = (ImageButton) findViewById(R.id.Back);
        ImageButton SettingsButton = (ImageButton) findViewById(R.id.Settings);
        ImageButton AddButton = (ImageButton) findViewById(R.id.Add);
        
        Button MapButton = (Button) findViewById(R.id.Map);
        Button ListsButton = (Button) findViewById(R.id.Lists);
        Button CalButton = (Button) findViewById(R.id.Cal);
        
        // stuff for trying to test dynamic addition of new buttons
        ArrayList<String> ListNames = new ArrayList<String>();
        ListNames.add("Work");
        ListNames.add("School"); 
        ListNames.add("Chores");
        
        // adding stuff to the scrollview - can get a button in, non-dynamically
//        ScrollView scroll = (ScrollView) this.findViewById(R.id.scrollview);
//        
//        Button listButton = new Button(this);
//        listButton.setText("Name of a List");
//
//        scroll.addView(listButton);
        
        // This ensures we have the most current manager state
        manage = Security.getManager();
        
        // Getting the field to input List buttons into
        LinearLayout itemList = (LinearLayout) findViewById(R.id.linearLayout5);
        
        // For each list the current manager contains, add a button with its name and set its click listener
        for(ToDoList list : manage.getToDoList()) {
        	Button newListButton = new Button(this);
        	newListButton.setText(list.getName());
        	newListButton.setOnClickListener(this);
        	itemList.addView(newListButton);
        }
        
        // Listening to Register Add item Button button event
        AddButton.setOnClickListener(new View.OnClickListener() {

        	public void onClick(View arg0) {
        		//Starting a new Intent
        		Intent nextScreen = new Intent(getApplicationContext(), CreateToDoListScreenActivity.class);
        		//Switches over to CreateItemActivity
        		finish();
        		startActivity(nextScreen);

        	}
        });
        
        BackButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), CS2340AndroidUDTActivity.class);
        		finish();
        		startActivity(nextScreen);
        	}
			
		});
        
        MapButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), MapScreenActivity.class);
        		finish();
        		startActivity(nextScreen);
        	}
			
		});
      }
    
    // This method is passed into newly created List buttons with the this attribute. Sets their action listener to move to ListViewActivity
	public void onClick(View view) {
		//Starting a new Intent
		Intent nextScreen = new Intent(getApplicationContext(), ListViewActivity.class);
		manage.setCurrentList((((Button)view).getText()).toString());
		Security.updateManager(manage);
		finish();
		//Switches over to CreateItemActivity
		startActivity(nextScreen);
		
	}
	
	
}
